home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / Syn Text Editor 2.1.0.46 / synsetup-2.1.0.46.exe / {app} / scripts / mhead.vbs < prev    next >
Text File  |  2003-08-13  |  8KB  |  261 lines

  1. ' Caption: Module Header...|
  2. ' Hint: Add Module Header|
  3. ' Icon: mhead.ico|
  4. '
  5. '  syn
  6. '  Copyright (C) 2000-2003, Ascher Stefan. All rights reserved.
  7. '  stievie@utanet.at, http://web.utanet.at/ascherst/
  8. '
  9. '  The contents of this file are subject to the Mozilla Public License
  10. '  Version 1.1 (the "License"); you may not use this file except in compliance
  11. '  with the License. You may obtain a copy of the License at
  12. '  http://www.mozilla.org/MPL/
  13. '
  14. '  Software distributed under the License is distributed on an "AS IS" basis,
  15. '  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
  16. '  the specific language governing rights and limitations under the License.
  17. '
  18. '  The Original Code is mhead.vbs, released Sun, 26 May 2002 10:55:39 UTC.
  19. '
  20. '  The Initial Developer of the Original Code is Ascher Stefan.
  21. '  Portions created by Ascher Stefan are Copyright (C) 2000-2003 Ascher Stefan.
  22. '  All Rights Reserved.
  23. '
  24. '  Contributor(s): .
  25. '
  26. '  Alternatively, the contents of this file may be used under the terms of the
  27. '  GNU General Public License Version 2 or later (the "GPL"), in which case
  28. '  the provisions of the GPL are applicable instead of those above.
  29. '  If you wish to allow use of your version of this file only under the terms
  30. '  of the GPL and not to allow others to use your version of this file
  31. '  under the MPL, indicate your decision by deleting the provisions above and
  32. '  replace them with the notice and other provisions required by the GPL.
  33. '  If you do not delete the provisions above, a recipient may use your version
  34. '  of this file under either the MPL or the GPL.
  35. '
  36. '  You may retrieve the latest version of this file at the syn home page,
  37. '  located at http://syn.sourceforge.net/
  38. '
  39. ' $Id: mhead.vbs,v 1.5.2.5 2003/08/13 00:38:45 neum Exp $
  40.  
  41. option explicit
  42.  
  43. '#include <cmnfunc>
  44. '#include <consts>
  45.  
  46. const RegKey = "HKCU\Software\Ascher\syn\Macros"
  47. dim MHForm
  48. dim EditName, EditPurpose, EditAuthor, EditCopy, EditDate, EditState
  49. dim chkTop
  50.  
  51. sub Main(FileName)
  52.   dim Label1, Label2, Label3, Label4, Label5, Label6, Label7
  53.   dim MemoDesc
  54.   dim BtnOK, BtnCancel
  55.   dim icofile
  56.   
  57.   if Documents.Count = 0 then
  58.     MsgBox "No Document open.", vbCritical
  59.     exit sub
  60.   end if
  61.  
  62.   MHForm = Create("TForm", Self)
  63.   with MHForm
  64.     .Caption = "Add Header"
  65.     .Position = "poOwnerFormCenter"
  66.     .BorderStyle = "bsSizeable"
  67.     .BorderIcons = "biSystemMenu"
  68.     icofile = ChangeFileExt(FileName, ".ico")
  69.     if FileExists(icofile) then
  70.       .Icon.LoadFromFile(icofile)
  71.     end if
  72.     .Width = 370
  73.     .Height = 250
  74.     .Constraints.MinHeight = Height
  75.     .Constraints.MinWidth = Width
  76.   end with
  77.   EditName = Create("TEdit", MHForm)
  78.   with EditName
  79.     .Parent = MHForm
  80.     .Anchors = "akLeft,akTop,akRight"
  81.     .Left = 80
  82.     .Top = 8
  83.     .Width = 200
  84.     .Text = ChangeFileExt(ActiveDocument.FileTitle, "")
  85.   end with
  86.   Label1 = Create("TLabel", MHForm)
  87.   with Label1
  88.     .Parent = MHForm
  89.     .Caption = "&Name:"
  90.     .Left = 8
  91.     .Top = 12
  92.     .FocusControl = EditName
  93.   end with
  94.   EditPurpose = Create("TEdit", MHForm)
  95.   with EditPurpose
  96.     .Parent = MHForm
  97.     .Anchors = "akLeft,akTop,akRight"
  98.     .Left = 80
  99.     .Top = 33
  100.     .Width = 200
  101.   end with
  102.   Label2 = Create("TLabel", MHForm)
  103.   with Label2
  104.     .Parent = MHForm
  105.     .Caption = "&Purpose:"
  106.     .Left = 8
  107.     .Top = 37
  108.     .FocusControl = EditPurpose
  109.   end with
  110.   EditAuthor = Create("TEdit", MHForm)
  111.   with EditAuthor
  112.     .Parent = MHForm
  113.     .Anchors = "akLeft,akTop,akRight"
  114.     .Left = 80
  115.     .Top = 58
  116.     .Width = 200
  117.     .Text = RegGetSettings(AddBackslash(RegKey) & "ah_author", "")
  118.   end with
  119.   Label3 = Create("TLabel", MHForm)
  120.   with Label3
  121.     .Parent = MHForm
  122.     .Caption = "&Author:"
  123.     .Left = 8
  124.     .Top = 62
  125.     .FocusControl = EditAuthor
  126.   end with
  127.   EditCopy = Create("TEdit", MHForm)
  128.   with EditCopy
  129.     .Parent = MHForm
  130.     .Anchors = "akLeft,akTop,akRight"
  131.     .Left = 80
  132.     .Top = 83
  133.     .Width = 200
  134.     .Text = RegGetSettings(AddBackslash(RegKey) & "ah_copy", "")
  135.   end with
  136.   Label4 = Create("TLabel", MHForm)
  137.   with Label4
  138.     .Parent = MHForm
  139.     .Caption = "&Copyright:"
  140.     .Left = 8
  141.     .Top = 87
  142.     .FocusControl = EditCopy
  143.   end with
  144.   EditDate = Create("TEdit", MHForm)
  145.   with EditDate
  146.     .Parent = MHForm
  147.     .Anchors = "akLeft,akTop,akRight"
  148.     .Left = 80
  149.     .Top = 108
  150.     .Width = 200
  151.     .Text = Now
  152.   end with
  153.   Label5 = Create("TLabel", MHForm)
  154.   with Label5
  155.     .Parent = MHForm
  156.     .Caption = "&Date/Time:"
  157.     .Left = 8
  158.     .Top = 112
  159.     .FocusControl = EditDate
  160.   end with
  161.   MemoDesc = Create("TMemo", MHForm)
  162.   with MemoDesc
  163.     .Parent = MHForm
  164.     .Anchors = "akLeft,akTop,akRight,akBottom"
  165.     .Left = 80
  166.     .Top = 133
  167.     .Width = 285
  168.     .Height = 110
  169.     .ScrollBars = "ssBoth"
  170.   end with
  171.   Label6 = Create("TLabel", MHForm)
  172.   with Label6
  173.     .Parent = MHForm
  174.     .Caption = "D&escription:"
  175.     .Left = 8
  176.     .Top = 133
  177.     .FocusControl = MemoDesc
  178.   end with
  179.  
  180.   BtnOK = Create("TButton", MHForm)
  181.   with BtnOK
  182.     .Parent = MHForm
  183.     .Anchors = "akTop,akRight"
  184.     .Caption = "&Insert"
  185.     .Default = true
  186.     .ModalResult = mrOK
  187.     .Left = 290
  188.     .Top = 7
  189.     .Width = 75
  190.     .Hint = "Insert Header"
  191.   end with
  192.   BtnCancel = Create("TButton", MHForm)
  193.   with BtnCancel
  194.     .Parent = MHForm
  195.     .Caption = "Cancel"
  196.     .Cancel = true
  197.     .ModalResult = mrCancel
  198.     .Left = 290
  199.     .Top = 40
  200.     .Width = 75
  201.     .Anchors = "akTop,akRight"
  202.     .Hint = "Close this Dialog"
  203.   end with
  204.   chkTop = Create("TCheckBox", MHForm)
  205.   with chkTop
  206.     .Parent = MHForm
  207.     .Anchors = "akTop,akRight"
  208.     .Caption = "&Top of file"
  209.     .Hint = "At the Top of the file, or at the current Caret Pos"
  210.     .Top = 85
  211.     .Left = 290
  212.     .Width = 80
  213.     .Checked = RegGetSettings(AddBackslash(RegKey) & "ah_top", true)
  214.   end with
  215.   with MHForm
  216.     .Width = RegGetSettings(AddBackslash(RegKey) & "ah_width", .Width)
  217.     .Height = RegGetSettings(AddBackslash(RegKey) & "ah_height", .Height)
  218.   end with
  219.   if MHForm.ShowModal = mrOK then
  220.     dim i, o
  221.     if chkTop.Checked then
  222.       o = 0
  223.     else
  224.       o = ActiveDocument.CaretY - 1
  225.     end if
  226.     with ActiveDocument.Lines
  227.       .Insert o, String(75, "*")
  228.       .Insert o + 1, "*" & Space(73) & "*"
  229.       .Insert o + 2, "* Name       : " & EditName.Text & Space(GetSpaceCount(EditName.Text)) & "*"
  230.       .Insert o + 3, "* Purpose    : " & EditPurpose.Text & Space(GetSpaceCount(EditPurpose.Text)) & "*"
  231.       .Insert o + 4, "* Author     : " & EditAuthor.Text & Space(GetSpaceCount(EditAuthor.Text)) & "*"
  232.       .Insert o + 5, "* Copyright  : " & EditCopy.Text & Space(GetSpaceCount(EditCopy.Text)) & "*"
  233.       .Insert o + 6, "* Date       : " & EditDate.Text & Space(GetSpaceCount(EditDate.Text)) & "*"
  234.       .Insert o + 7, "* Description: " & MemoDesc.Lines(0) & Space(GetSpaceCount(MemoDesc.Lines(0))) & "*"
  235.       for i = 1 to MemoDesc.Lines.Count - 1
  236.         .Insert o + i + 7, "*              " & MemoDesc.Lines(i) & Space(GetSpaceCount(MemoDesc.Lines(i))) & "*"
  237.       next
  238.       .Insert o + 7 + i, "*" & Space(73) & "*"
  239.       .Insert o + 8 + i, String(75, "*")
  240.     end with
  241.     ActiveDocument.SelectRange 1, o + 1, 1, o + i + 10
  242.     ActiveDocument.ExecCommand scEComment
  243.     ActiveDocument.SelectRange 1, o + 1, 1, o + 1
  244.   end if
  245.  
  246.   RegSetSettings AddBackslash(RegKey) & "ah_author", EditAuthor.Text
  247.   RegSetSettings AddBackslash(RegKey) & "ah_copy", EditCopy.Text
  248.   RegSetSettings AddBackslash(RegKey) & "ah_top", chkTop.Checked
  249.   RegSetSettings AddBackslash(RegKey) & "ah_width", MHForm.Width
  250.   RegSetSettings AddBackslash(RegKey) & "ah_height", MHForm.Height
  251.   MHForm.Free
  252. end sub
  253.  
  254. function GetSpaceCount(s)
  255.   if Len(s) < 59 then
  256.     GetSpaceCount = 59 - Len(s)
  257.   else
  258.     GetSpaceCount = Len(s)
  259.   end if
  260. end function
  261.